package com.example.springbootamqpconsumer.lister;

import com.example.springbootamqpconsumer.utils.AilCodeUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class ConsumerLister {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

     @RabbitListener(queues = "java-queue")
    public void getMsg(Message message, String phone) throws Exception{
         System.out.println("我接收到了消息:"+phone);
         AilCodeUtils ailCodeUtils=new AilCodeUtils();
         ailCodeUtils.sendLoginCode(phone,"123455");
         stringRedisTemplate.opsForValue().set(phone,"123455");
         stringRedisTemplate.expire(phone,5, TimeUnit.MINUTES);
     }
}
